﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;
using static ServerGame.Manager.Efun;

namespace ServerGame.Manager
{
    public enum EPropType
    {
        basic,
        adj,
    }
    /// <summary>
    /// 管理 战斗
    /// </summary>
    public static partial class CombatMgr
    {
        public static EPropType PropType(this EProp prop)
        {
            return true switch
            {
                _ when prop <= EProp.efsen => EPropType.basic,
                _ => EPropType.adj
            };
        }
        public static long PropCbt(this MudChar obj, EPropCbt propcbt)
        {
            //if (obj.Type == EMudObjType.Player)
            //{
            //    return (obj as Player).PropCbtPlayer(propcbt);
            //}
            //else
            //{
            //    return (obj as Npc).PropCbtNpc(propcbt);
            //}
            long val = 0;

            //等级转化为战斗力
            long Level2Power(int level) 
            {
                return level + true switch
                {
                    _ when level > 300 => 35 + (level - 300) * 2 / 5,
                    _ when level > 200 => 15 + (level - 200) / 5,
                    _ when level > 100 => 5 + (level - 100) / 10,
                    _ => level / 20
                };
            }

            switch (propcbt)
            {
                case EPropCbt.damage:
                    {
                        val += obj[EProp.damage];
                        if (obj.ActEquipUsageType == EUsageType.扑击格斗)
                        {
                            val += obj[EProp.str];
                        }
                    }
                    break;
                case EPropCbt.armor:
                    {
                        val += obj[EProp.armor];
                    }
                    break;
                case EPropCbt.attack:
                    {
                        val += obj[EProp.kar];
                        val += obj[EProp.cattack];
                        if (obj.ActEquipUsageType == EUsageType.扑击格斗)
                        {
                            obj.UsageGet(EUsageType.扑击格斗, out _, out var level);
                            val += Level2Power(level);
                        }
                        else
                        {
                            obj.UsageGet(obj.ActEquipUsageType, out _, out var level);
                            val += Level2Power(level);
                        }
                    }
                    break;
                case EPropCbt.defence:
                    {
                        val += obj[EProp.cdefence];
                        val += obj.PropCbt(EPropCbt.dodge);
                        val += obj.PropCbt(EPropCbt.parry);
                    }
                    break;
                case EPropCbt.dodge:
                    {
                        val += obj[EProp.cdodge];
                        obj.UsageGet(EUsageType.基本轻功, out _, out var level);
                        val += Level2Power(level);
                    }
                    break;
                case EPropCbt.parry:
                    {
                        val += obj[EProp.cparry];
                        obj.UsageGet(EUsageType.拆招卸力, out _, out var level);
                        val += Level2Power(level);
                    }
                    break;
                case EPropCbt.force:
                    {
                        val += obj[EProp.cforce];
                        obj.UsageGet(EUsageType.基本内功, out _, out var level);
                        val += Level2Power(level);
                    }
                    break;
                case EPropCbt.spell:
                    {
                        val += obj[EProp.cspell];
                        obj.UsageGet(EUsageType.基本法术, out _, out var level);
                        val += Level2Power(level);
                    }
                    break;
                default:
                    break;
            }
            return val;
        }
        public static long PropCbtPlayer(this Player obj, EPropCbt propcbt)
        {
            return 0;
        }
        public static long PropCbtNpc(this Npc obj, EPropCbt propcbt)
        {
            return 0;
        }
    }
}
